<template>
  <div ref="attachmentDetListRef" class="attachDetailList">
    <MyTable
      id="fileId"
      ref="myTableRef"
      :is-mar-class="true"
      :table-data="tableData"
      :columns="colOption"
      :table-operation="binConfig"
      :col-option-enum="dicLists"
      :is-selection="false"
      @propClick="btnClick"
    >
      <template #headerLeft>
        <el-form :model="tableForm" label-width="160px" class="pms-details" size="mini" :disabled="false" :inline="true">
          <el-form-item label="请选择上传文件的项目阶段">
            <el-select
              v-model="tableForm.prjStage"
              class="tablePrjStage"
              :popper-append-to-body="false"
              clearable
              placeholder="请选择"
              @focus="focusPrjStage"
              @change="changePrjPhase"
            >
              <el-option
                v-for="item in dicLists['PRO_STAGE']"
                :key="item.dictId"
                :label="item.dictName"
                :value="item.dictId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="项目节点">
            <el-select v-model="tableForm.nodeId" clearable placeholder="请选择" @change="changePrjNode">
              <el-option
                v-for="item in dicLists['ATT_PRO_NODE']"
                :key="item.dictId"
                :label="item.dictName"
                :value="item.dictId"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </template>
      <template #fileName="{ scope }">
        <el-button type="text" @click="preview(scope)">{{ scope.fileName }}</el-button>
      </template>
      <!-- 文档载体 -->
      <template #docCarrierType="{ scope }">
        <span style="display: none;">{{ docCarrierTypeEnum[scope.docCarrierType] }}</span>
        <!-- <el-tooltip v-if="prjParams.prjType == 'M'" :content="docCarrierTypeEnum[scope.docCarrierType]">
          <div>{{ docCarrierTypeEnum[scope.docCarrierType] }}</div>
        </el-tooltip> -->
        <el-select v-model="scope.docCarrierType" :disabled="scope.docCarrierType == '1'" @change="documentCarrier(scope)">
          <el-option label="电子文档" value="0" />
          <el-option label="纸质文档" value="1" />
        </el-select>
        <!-- <el-select v-else v-model="scope.docCarrierType" :disabled="scope.docCarrierType == '1'" @change="documentCarrier(scope)">
          <el-option label="电子文档" value="0" />
          <el-option label="纸质文档" value="1" />
        </el-select> -->
      </template>
      <!-- 删除 -->
      <template #operation="{ scope }">
        <div v-if="scope.operAteType == '2'">
          <el-button
            class="pms-button-primary-plain"
            @click="delClk(scope)"
          >删除</el-button>
        </div>
      </template>
    </MyTable>
    <pagination
      v-if="pageParam.total > 10"
      :total="pageParam.total"
      :page.sync="pageParam.pageNum"
      :limit.sync="pageParam.pageSize"
      @pagination="doSearch"
    />
    <!-- 替换 / 上传 / 指派签署人 -->
    <el-dialog
      v-if="dialogUpload"
      ref="dialogUploadRef"
      v-dialogDrag
      :append-to-body="true"
      :modal-append-to-body="true"
      :modal="true"
      :close-on-click-modal="false"
      :title="dialogTitle"
      height="60%"
      width="50%"
      class="pms-dialog"
      :visible.sync="dialogUpload"
      @close="() => { isShowStampUnit = false; dialogClosed() }"
    >
      <div class="signatoryBody">
        <UploadAttach
          v-if="isUploadBtn"
          ref="uploadAttachRef"
          :prj-file-type-option="prjFileTypeOption"
          :prj-upload-data="prjUploadData"
          :prj-data="prjData"
          :is-replace="isReplace"
          :is-att-info-item-mar="true"
          @changeSignatory="changeSignatory"
        />
        <ChooseSignatory v-if="isShowStampUnit" ref="chooseSignatoryRef" :prj-data="prjData">
          <template #remarks>
            <Signatory :is-signatory="!isUploadBtn" />
          </template>
        </ChooseSignatory>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="pms-zr-button-primary" style="background-color: #eb4b4b; color: #fff;" type="primary" size="small" @click="batchUploadClick">
          提 交
        </el-button>
        <el-button
          class="pms-zr-button-primary pms-zr-ClosedBtn"
          style="background-color: #eb4b4b; color: #fff;"
          size="small"
          @click="() => { dialogUpload = false;isShowStampUnit = false }"
        >
          取 消
        </el-button>
      </div>
    </el-dialog>
    <!-- 预览 -->
    <!-- 文件预览 -->
    <el-dialog
      v-if="dialogFileView"
      ref="dialogViewRef"
      v-dialogDrag
      :append-to-body="true"
      :modal-append-to-body="true"
      :modal="true"
      :close-on-click-modal="false"
      title="预览"
      height="60%"
      width="60%"
      class="pms-dialog"
      :visible.sync="dialogFileView"
      @close="dialogClosed"
    >
      <div class="signatoryPre">
        <FilePreview ref="filePreviewRef" class="filePreviewClass" :file-obj="fileObj" />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          class="pms-zr-button-primary"
          style="background-color: #eb4b4b; color: #fff;"
          size="small"
          @click="dialogFileView = false"
        >
          取 消
        </el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      title="档案归档"
      :visible.sync="dialogVisible"
      width="50%"
      modal
      class="pms-dialog"
      style="text-align: justify;"
    >
      <div style="margin-bottom: 20px;margin-left: 9%;">是否对项目向档案系统发起归档操作？</div>
      <el-form v-if="remarksShow" ref="form" :inline="true" :model="form" class="" label-width="160px" size="mini" :rules="rules" style="height: 80px">
        <el-row :gutter="22">
          <el-col :span="22">
            <el-form-item label="备注信息" prop="remarks" style="width: 100%;">
              <el-input v-model="form.remarks" resize="none" maxlength="1500" :autosize="{ minRows: 4, maxRows: 4}" type="textarea" placeholder="字数上限为1500字" min-height="80px" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="formBott">
        <el-button class="pms-button-primary" type="primary" @click="newSave()">确定</el-button>
        <el-button class="pms-button-primary" @click="close()">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'
import MyTable from '@/components/basic/myTable'
import Signatory from '@/components/attachmentInfo/signatory'
import ChooseSignatory from '@/components/attachmentInfo/chooseSignatory'
import UploadAttach from '@/components/attachmentInfo/uploadAttachOld.vue'
import FilePreview from '@/components/business/filePreview.vue'
import SysConst from '@/common/const'
import { getDropdownData } from '@/api/common' // 字典接口
import { getTypeInfoApi, getNodeInfoApi } from '@/api/attachManagement/attachments/attachmentDetails'
import { getQueryObject, disableScroll, enableScroll, msgInfoEl } from '@/utils'
import {
    getPrjArchivesFile,
    getPrjFileTypeApi,
    batchUploadApi,
    getPrjStageApi,
    uploadSignInfoApi,
    pushArchives,
    pushDelete,
    checkUploadArchives,
    downloadApi, getWPSToken, getPreviewFile, querySuffix // 单个文件下载
} from '@/api/attachmentInfo'
import $ from 'jquery'
const Base64 = require('js-base64').Base64
const binConfig = [
    { label: '归档', fun: 'archivist', type: '' }
]
const colOption = [
    { label: '项目阶段', width: '120', prop: 'prjStage', dicType: 'PRO_STAGE', dicProp: { label: 'dictName', value: 'dictId' }},
    { label: '项目节点', width: '150', prop: 'nodeName' },
    { label: '文件类型', width: '150', prop: 'docTypeName' },
    { label: '文件名称', width: '', prop: 'fileName' },
    { label: '文件获取方式', width: '140', prop: 'fileSource', filter: { '0': '手动上传', '1': '系统生成', '2': '系统生成/手动编辑' }}, // 0-手动上传，1-系统生成，2-系统生成/手动编辑
    { label: '文件上传人', width: '100', prop: 'uploaderName' },
    { label: '单位', width: '100', prop: 'orgName' },
    { label: '文件获取时间', width: '120', prop: 'uploadTime' },
    { label: '档案状态', width: '120', prop: 'manageState', filter: { '0': '未归档', '1': '已推送', '2': '收集', '3': '移交', '4': '归档', '5': '重新收集' }},
    { label: '文档载体', width: '160', prop: 'docCarrierType', isShowTooltip: true },
    { label: '备注', width: '160', prop: 'message' },
    { label: '操作', width: '160', prop: 'operation' }
    // { label: '是/否电子签章', width: '', prop: 'isSignature', filter: { '1': '是', '0': '否' }},
    // { label: '签署状态', width: '', prop: 'signatureStatus', dicType: 'SIGN_STATE', dicProp: { label: 'dictName', value: 'dictId' }},
    // { label: '是/否审计必审', width: '120', prop: 'isAudit', filter: { '1': '是', '0': '否' }}
]

export default {
    name: 'AttachDetailList',
    components: {
        MyTable,
        Signatory,
        ChooseSignatory,
        UploadAttach,
        FilePreview
    },
    data() {
        return {
            tableData: [], // 列表数据
            colOption,
            dicLists: {}, // 字典数据集合
            tableForm: {
                prjStage: '', // 选择项目阶段
                nodeId: '' // 项目节点
            },
            dialogUpload: false, // 上传附件弹框
            isShowStampUnit: false, // 是否展示签署单位
            prjFileTypeOption: [], // 上传文件类型数据选项
            prjUploadData: {}, // 替换数据
            prjData: {}, // 项目数据信息
            docCarrierTypeEnum: {
                '0': '电子文档',
                '1': '纸质文档'
            },
            isReplace: true, // 是否替换
            fileObj: {}, // 预览文件地址
            dialogFileView: false, // 预览弹框
            isUploadBtn: false, // 是否点击上传或替换
            pageHeight: 180, // 附件列表页面默认高度
            prjParams: {}, // 页面路由参数集
            // 列表按钮配置枚举
            binConfig,
            // 分页信息
            pageParam: {
                pageSize: SysConst.PAGESIZE, // 每页显示val条
                pageNum: SysConst.CURRENT_PAGE, // 当前页
                total: SysConst.TOTAL // 总数
            },
            dialogVisible: false,
            remarksShow: false,
            form: {
                remarks: ''
            },
            rules: {
                // projectProGress: [{ required: true, message: 'null', trigger: 'change' }]
            },
            wpsToken: '',
            previewObj:{}
        }
    },
    created() {
        const {
            prjId,
            isChange = '0',
            operateType = '2',
            settPageType,
            prjType
        } = getQueryObject()
        if (prjType === 'M') {
            this.colOption = this.colOption.filter(item => item.prop !== 'docCarrierType')
        }
        this.prjParams = {
            prjId, // 项目id
            isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
            operateType, // 操作类型，1:新增，2:补传
            settPageType, // 结算可上传阶段标识
            prjType // 是否是通信项目
        }

        this.getDictData()
        this.getPrjStage()
        this.getToken()
        this.doSearch()
        this.querySuffix()
    },
    mounted() {
        window.parent.postMessage({ height: 130, type: 'attachment' }, this.$fixIframeArr())
        console.log(150, this.pageHeight, 'this.pageHeight-false')
    },
    methods: {
        querySuffix() {
            querySuffix().then((res) => {
                if (+res.code === 200) {
                    this.previewObj = res.data
                }
            })
        },
        getToken() {
            getWPSToken().then((res) => {
                if (+res.code === 200) {
                    this.wpsToken = res.data
                }
            })
        },
        // 查询
        queryPrjFileInfo(params, item) {
            getPrjArchivesFile(params).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                console.log(res, '附件信息')
                this.tableData = res.data.records
                this.pageParam.total = res.data?.total || 0
                this.pageParam.pageSize = item?.limit || SysConst.PAGESIZE
                this.pageParam.pageNum = item?.page || SysConst.CURRENT_PAGE
                this.$nextTick(() => {
                    const h = this.$refs.attachmentDetListRef.clientHeight
                    this.pageHeight = res.data.records.length ? h : 130
                    window.parent.postMessage({ height: this.pageHeight, type: 'attachment' }, this.$fixIframeArr())
                    console.log(h, this.pageHeight, 'this.pageHeight-true')
                })
            })
        },
        // 分页查询
        doSearch(item) {
            const params = {
                pageNum: item?.page || SysConst.CURRENT_PAGE,
                pageSize: item?.limit || SysConst.PAGESIZE,
                prjId: this.prjParams.prjId
            }
            this.queryPrjFileInfo(params, item)
        },
        // 当父组件接收到了子组件this.$emit的通知后就会执行这个方法来接收子组件点击传递过来的数据
        btnClick(fun, row) {
            this[fun](row)
        },
        // 归档
        archivist() {
            console.log(this.prjParams.prjType)
            this.dialogVisible = true
            if (this.prjParams.prjType === 'M') {
                 this.remarksShow = false
            } else {
                 this.remarksShow = true
            }
            // dialogVisible: false,
            // remarksShow: false,
            // 在这里调用归档接口和逻辑
            // * 仅支持本页面上传的文件
            // 将弹框挂载在最外层

            // const contentBody = window.top.document.body
            // this.$confirm('是否对项目向档案系统发起归档操作?', '归档', {
            //     confirmButtonText: '确定',
            //     cancelButtonText: '取消',
            //     type: 'warning',
            //     closeOnClickModal: false
            // }).then(() => {
            //     pushArchives({ prjId: this.prjParams.prjId }).then(res => {
            //         if (+res.code !== 200) return Promise.reject(res)
            //         this.dialogUpload = false
            //         this.doSearch()
            //         msgInfoEl({
            //             type: 'success',
            //             message: res.message
            //         })
            //     })
            //     enableScroll(contentBody)
            // }).catch(() => {
            //     enableScroll(contentBody)
            // })
            // this.$nextTick(() => {
            //     const msgBox = document.querySelector('.el-message-box__wrapper')
            //     contentBody.appendChild(msgBox)
            //     disableScroll(contentBody)
            // })
        },
        // 归档确认
        newSave() {
            const remarksVal = this.form.remarks
            if (this.prjParams.prjType !== 'M') {
                if (remarksVal.length < 1) {
                    return msgInfoEl({
                            type: 'warning',
                            message: '请输入备注'
                        })
                }
                if (remarksVal.length > 1500) {
                    return msgInfoEl({
                            type: 'warning',
                            message: '备注字数上限为1500字'
                        })
                }
            }
            pushArchives({ prjId: this.prjParams.prjId, remarks: remarksVal, notVerify: '1' }).then(res => {
                this.dialogVisible = false
                this.form.remarks = ''
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                this.dialogUpload = false
                this.doSearch()
                msgInfoEl({
                    type: 'success',
                    message: res.message
                })
            })
            console.log(this.form.remarks.length, 'this.form.remarks')
        },
        // 归档取消
        close() {
            this.dialogVisible = false
            this.form.remarks = ''
        },
        // 下拉框获取焦点事件
        focusPrjStage() {
            // 设置下拉框样式
            const tablePrjStage = document.querySelector('.tablePrjStage')
            const scrollbar = tablePrjStage.querySelector('.el-scrollbar__wrap')
            const h = this.$refs.attachmentDetListRef.clientHeight - 26
            scrollbar.style.height = h + 'px'
            scrollbar.style.overflowX = 'hidden'
            scrollbar.style.marginBottom = '-8px'
        },
        // 改变项目阶段事件
        changePrjPhase() {
            this.tableForm.prjStage ? this.getNodeInfo(this.tableForm.prjStage) : this.$set(this.dicLists, 'ATT_PRO_NODE', [])
            this.tableForm.nodeId = ''
        },
        // 改变项目节点事件
        async changePrjNode() {
            // 信息化归档补传前校验状态
            const checkUpArVal = await checkUploadArchives({ prjId: this.prjParams.prjId })
            if (+checkUpArVal.code !== 200) {
                return
            }

            if (!this.tableForm.nodeId) {
                return
            }
            const res = await this.getTypeInfo({ prjId: this.prjParams.prjId, prjStage: this.tableForm.prjStage })
            this.getPrjFileType(res.data)
            this.dialogTitle = '上传'
            this.isReplace = false
            this.isUploadBtn = true
            this.dialogUpload = true
            this.dialogEl('dialogUploadRef')
        },
        // 获取上传前的参数
        async getTypeInfo(params) {
            const res = await getTypeInfoApi(params)
            if (res.success) {
                this.prjParams = { ...this.prjParams, ...res.data }
                console.log(this.prjParams, '上传前的参数--res')
                return res
            }
        },
        // 上传附件中-签署人改变事件
        changeSignatory(val1, val2) {
            this.isShowStampUnit = val1
            this.prjData = {
                docType: val2,
                proStage: this.tableForm.prjStage,
                prjId: this.prjParams.prjId
            }
        },
        // 上传事件
        batchUploadClick() {
            const uploadForm = this.$refs.uploadAttachRef.uploadForm
            // const signatoryData = this.$refs.chooseSignatoryRef.getSelectionSignatory
            // 备注：uploadForm.isEleSign === '0' => 附件上传; uploadForm.isEleSign === '1' => 电子签章上传
            if (uploadForm.isEleSign === '0') {
                this.attachmentUpload(uploadForm)
            } else {
                this.eleSignUpload(uploadForm)
            }
        },
        // 附件上传
        attachmentUpload(uploadForm) {
            const {
                prjId, // 项目id
                fileSupplierCode = '', // 供应商编码
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                prjType,
                buildModes,
                towerType,
                roomType,
                operateType // 操作类型，1:新增，2:补传
            } = this.prjParams
            if (this.isUploadBtn && !uploadForm.fileList.length) {
                return msgInfoEl({
                    type: 'info',
                    message: '请上传文件'
                })
            }

            const params = {
                file: uploadForm.fileList[0].raw, // 文件
                docFileType: uploadForm.docTypeCode, // 文件类型
                prjId, // 项目id
                activityId: this.tableForm.nodeId, // 流程id
                prjStage: this.tableForm.prjStage, // 项目阶段
                prjType,
                buildModes,
                towerType,
                roomType,
                fileSupplierCode, // 供应商编码
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                operateSystem: '0', // 操作系统，0:PMS,1:施工管理
                operateType // 操作类型，1:新增，2:补传
            }
            const formData = new FormData()
            Object.keys(params).forEach(key =>
                formData.append(key, params[key])
            )
            batchUploadApi(formData).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                this.dialogUpload = false
                this.doSearch()
                msgInfoEl({
                    type: 'success',
                    message: res.message
                })
            })
        },
        // 电子签章上传
        eleSignUpload(uploadForm) {
            const {
                prjId, // 项目id
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                prjType,
                buildModes,
                towerType,
                roomType,
                operateType // 操作类型，1:新增，2:补传
            } = this.prjParams
            if (this.isUploadBtn && !uploadForm.fileList.length) {
                return msgInfoEl({
                    type: 'info',
                    message: '请上传文件'
                })
            }
            const params = {
                file: this.isUploadBtn ? uploadForm.fileList[0].raw : {}, // 文件
                docFileType: this.isUploadBtn ? uploadForm.docTypeCode : this.prjData.docType, // 文件类型
                prjId, // 项目id
                prjStage: this.isUploadBtn ? this.tableForm.prjStage : this.prjData.proStage, // 项目阶段
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                operateType, // 操作类型，1:新增，2:补传
                operateSystem: '0', // 操作系统 0:PMS,1:施工管理
                oldDocId: this.isUploadBtn ? '' : this.prjData.fileId,
                activityId: this.tableForm.nodeId, // 流程id
                prjType,
                buildModes,
                towerType,
                roomType,
                isReplaceFlag: this.isReplace ? 'Y' : 'N'
            }
            const formData = new FormData()
            Object.keys(params).forEach(key =>
                formData.append(key, params[key])
            )
            uploadSignInfoApi(formData).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                this.dialogUpload = false
                this.doSearch()
                msgInfoEl({
                    type: 'success',
                    message: res.message
                })
            })
        },
        getUserId(){
            let str='';
            if(sessionStorage.getItem('SET_LOGINDATA')){
              str = JSON.parse(sessionStorage.getItem('SET_LOGINDATA')).staffId
            }else if(sessionStorage.getItem('userInfo')){
              str = JSON.parse(sessionStorage.getItem('userInfo')).staffId
            }else{
              console.log('')
            }
            console.log('str',str)
            return str;
        },
        // 点击文件名称-预览
        async preview(row) {
            if (row.isSignature === '1') {
                this.getSignFlowDocUrls(row.fileViewId)
                return
            } else {
                const types = row.fileName.substring(row.fileName.lastIndexOf('.') + 1)
                const previewArray = Object.keys(this.previewObj);
                if (previewArray.includes(types)) {
                    const params = {
                        fileId: row.fileId,
                        type: this.previewObj[types],
                        userId: this.getUserId(),
                        token: this.wpsToken
                    }
                    getPreviewFile(params).then((res) => {
                        // if(+res.code===200){
                        //     const newWin = window.open()
                        //     const form = $("<form method='post'></form>")
                        //     form.attr({ action: res.data })
                        //     form.appendTo(newWin.document.body)
                        //     form.submit()
                        // }
                        if (+res.code === 200 && res.data) {
                            window.open(res.data, '_blank')
                        }
                    })
                } else {
                    return msgInfoEl({
                        type: 'info',
                        message: `所选文件不支持预览`
                    })
                }
            }
            // let res = {}
            // const params = {
            //     fileId: row.fileId,
            //     fileName: row.fileName
            // }
            // await downloadApi(params).then(r => {
            //     res = r
            // })
            // const blob = new Blob([res.data], { type: 'application/pdf;charset-UTF-8' })
            // const url = window.URL.createObjectURL(blob)
            // row.filePath = url
            // this.fileObj = {}
            // if (!row.filePath) {
            //     return msgInfoEl({
            //         type: 'info',
            //         message: `所选${row.fileName}文件不支持预览`
            //     })
            // }
            // const types = row.fileName.substring(row.fileName.lastIndexOf('.') + 1)
            // if (['word', 'docx', 'excel', 'xlsx'].includes(types)) {
            //     console.log(types, '12')
            //     window.open(this.$router.resolve({
            //         name: 'FilePreview',
            //         query: {
            //             type: types,
            //             fileSrc: row.filePath
            //         }
            //     }).href, '_blank')
            //     return
            // }
            // // if (['xls'].includes(types)) {
            // //     msgInfoEl({
            // //         type: 'info',
            // //         message: '不支持预览xls文件, 请下载'
            // //     })
            // //     return
            // // }
            // if (['pdf'].includes(types)) {
            //     window.open(row.filePath, '_blank')
            //     return
            // }
            // if (['pptx', 'ppt', 'doc', 'xls'].includes(types)) {
            //     // window.open('http://10.180.30.51:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(row.filePath)), '_blank')
            //     // window.open('http://120.52.136.29:18088/preview/onlinePreview?url=' + encodeURIComponent(Base64.encode(row.filePath)), '_blank')
            //     // window.open(`${process.env.VUE_APP_BASE_API}preview/onlinePreview?url=${encodeURIComponent(Base64.encode(row.filePath))}`, '_blank')
            //     return msgInfoEl({
            //         type: 'info',
            //         message: `所选文件不支持预览`
            //     })
            // }
            // if (['jpg', 'png', 'jpeg', 'bmp', 'mp3', 'mp4', 'webm', 'ogg', 'aac', 'wav'].includes(types)) {
            //     this.fileObj = {
            //         type: types,
            //         fileSrc: row.filePath
            //     }
            //     this.dialogFileView = true
            //     this.dialogEl('dialogViewRef')
            // } else if (['txt'].includes(types)) {
            //     axios.get(row.filePath, {
            //         responseType: 'blob',
            //         transformResponse: [
            //             async function(data) {
            //                 // txt转码
            //                 return await new Promise((resolve) => {
            //                     const reader = new FileReader()
            //                     reader.readAsText(data, 'UTF-8') // GBK UTF-8
            //                     reader.onload = () => {
            //                         resolve(reader.result)
            //                     }
            //                 })
            //             }
            //         ]
            //     }).then(res => {
            //         res.data.then((data) => {
            //             this.fileObj = {
            //                 type: types,
            //                 fileSrc: data
            //             }
            //         })
            //     })
            //     this.dialogFileView = true
            //     this.dialogEl('dialogViewRef')
            // } else {
            //     msgInfoEl({
            //         type: 'info',
            //         message: '不支持预览此文件'
            //     })
            // }
            // console.log(row, types, '预览')
        },
        // 获取附件允许上传文件类型数据
        getPrjFileType(res) {
            // const {
            //     prjType, // 项目类型
            //     buildModes, // 建设模式
            //     towerType, // 塔类型
            //     roomType, // 室分类型
            //     businessMajor,
            //     businessType
            // } = res
            const params = {
                ...res,
                ...this.tableForm
            }
            getPrjFileTypeApi(params).then(res_ => {
                if (+res_.code !== 200) {
                    return Promise.reject(res_)
                }
                this.prjFileTypeOption = res_.data
            })
        },
        // 获取字典数据
        async getDictData() {
            const arr = ['SIGN_STATE']
            const promises = arr.map(item => getDropdownData(item))
            const results = await Promise.all(promises)
            arr.forEach((item, i) => {
                this.$set(this.dicLists, item, results[i].data ?? [])
            })
            this.$set(this.dicLists, 'FILE_UPLOAD_MODES', SysConst.UPLOAD_MODES)
        },
        // 获取项目阶段字典
        async getPrjStage() {
            const res = await getPrjStageApi({ settPageType: this.prjParams.settPageType })
            const data = res.data.map(item => ({
                dictId: item.key,
                dictName: item.value
            }))
            this.$set(this.dicLists, 'PRO_STAGE', data)
        },
        // 获取项目节点字典
        async getNodeInfo(val) {
            const res = await getNodeInfoApi({ prjId: this.prjParams.prjId, settPageType: this.prjParams.settPageType, prjStage: val ?? '' })
            if (!res.data.length) {
                msgInfoEl({
                    type: 'info',
                    message: '此项目阶段下项目节点为空'
                })
            }
            this.$set(this.dicLists, 'ATT_PRO_NODE', res.data)
        },
        // 将弹框挂载在最外层
        dialogEl(refName) {
            // 将弹框挂载在最外层
            const contentBody = window.top.document.body
            this.$nextTick(() => {
                const dialogModal = document.querySelector('.v-modal')
                contentBody.appendChild(this.$refs[refName].$el)
                contentBody.appendChild(dialogModal)
                disableScroll(contentBody)
            })
        },
        // 关闭弹框
        dialogClosed() {
            const contentBody = window.top.document.body
            enableScroll(contentBody)
        },
        // 删除
        delClk(row) {
            // * 仅支持本页面上传的文件
            // 将弹框挂载在最外层
            const contentBody = window.top.document.body
            this.$confirm('确认删除所选数据, 是否继续?', '删除', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                cancelButtonClass: 'pms-zr-button',
                confirmButtonClass: 'pms-zr-button-primary',
                type: 'warning',
                closeOnClickModal: false
            }).then(() => {
                console.log('删除了')
                pushDelete({ prjId: this.prjParams.prjId, infoDocId: row.fileId }).then(res => {
                    if (+res.code !== 200) {
                        return Promise.reject(res)
                    }
                    this.dialogUpload = false
                    this.doSearch()
                    msgInfoEl({
                        type: 'success',
                        message: res.message
                    })
                })
                enableScroll(contentBody)
            }).catch(() => {
                console.log('取消删除了')
                enableScroll(contentBody)
            })
            this.$nextTick(() => {
                const msgBox = document.querySelector('.el-message-box__wrapper')
                contentBody.appendChild(msgBox)
                disableScroll(contentBody)
            })
        },
        documentCarrier(row) {
            console.log(row)
            // * 仅支持本页面上传的文件
            // 将弹框挂载在最外层
            // const contentBody = window.top.document.body
            // this.$confirm('确定文档载体吗, 是否继续?', '删除', {
            //     confirmButtonText: '确定',
            //     cancelButtonText: '取消',
            //     type: 'warning',
            //     closeOnClickModal: false
            // }).then(() => {
            //     console.log('了')
            //     enableScroll(contentBody)
            // }).catch(() => {
            //     console.log('取消了')
            //     enableScroll(contentBody)
            // })
            // this.$nextTick(() => {
            //     const msgBox = document.querySelector('.el-message-box__wrapper')
            //     contentBody.appendChild(msgBox)
            //     disableScroll(contentBody)
            // })
        }
    }
}
</script>

<style lang="scss" scoped>
.attachDetailList {
    // width: 100%;
    height: auto;
    margin: 0px 20px;
}
.pms-details {
    margin-right: 10px;
    display: flex;
    width: auto;
    justify-content: flex-end;
    .el-form-item {
        width: auto;
    }
}
::v-deep .btnBox-btns {
    // margin-right: 10px;
    margin-top: 4px;
}
.el-button--text {
    color: #02A7F0;
}
.signatoryBody {
    min-height: 170px;
    max-height: 420px;
    overflow-y: auto;
    overflow-x: hidden;
}
.signatoryPre {
    max-height: 420px;
    overflow-y: auto;
    overflow-x: hidden;
}
.el-button--primary {
    color: #fff;
}
::v-deep .pms-details .el-form-item .el-form-item__content {
    // width: 100%;
    width: 140px;
}
::v-deep .btnBox-btn {
    padding-right: 10px;
}
::v-deep .el-form-item .el-form-item__label {
    // line-height: 20px !important;
}
.formBott{
    text-align: center;
    margin-top: 20px;
}

</style>
